/*  tBookShelf: HyphenationManager
    (C) 2007  TvN (Volodymyr Tarasenko), e-mail: tvntsr@yahoo.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef HYPHENATION_MANAGER_HPP
#define HYPHENATION_MANAGER_HPP

#include <list>

#include "Utils/Hyphenation.hpp"

class HyphenationManager
{
    typedef std::list<HyphenDict*> HyphenDictList;
public:
    HyphenationManager()
        : mCurr(0)
    {}

    ~HyphenationManager()
    {
        for(HyphenDictList::iterator p = mDicts.begin();
            p != mDicts.end();
            ++p)
        {
            delete *p;
        }
    }

    void open(const std::string& dic)
    {
        std::cerr << "Open dictionary:"
                  << dic
                  << std::endl;
        std::auto_ptr<HyphenDict> dict (new HyphenDict(dic));

        mDicts.push_back(dict.get());
        mCurr = dict.release();

        std::cerr << "Done"
                  << std::endl;
    }

    void   selectDict(const std::string& enc_name);

    int    hyphenateString(std::string& str, 
                           std::string& rest, 
                           size_t max_len);
    size_t hyphenateString(const std::string& str, 
                           const size_t       max_len);
    
    /// hypenates the word, symbols up to '-' stored into word, 
    /// all other is copied into rest
    int hyphenateWord(std::string& word, 
                      std::string& rest, 
                      size_t       max_len);

    int hyphenateEncodedString(std::string& str, 
                               size_t       max_len, 
                               const std::string& enc_name);
private:
    HyphenDictList mDicts;
    HyphenDict*    mCurr;
};

#endif //HYPHENATION_MANAGER_HPP
